package bigraph.commands;

import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.commands.Command;

import bigraph.model.Root;
import bigraph.model.Canvas;

public class RootCreateCommand extends Command {

	private Root root;
	private Canvas canvas;
	
	public RootCreateCommand() {
	     super();
	     root = null;
	     canvas = null;
	}
	public void setRoot(Object s) {
	     if (s instanceof Root)
	            this.root = (Root)s;
	}
	public void setCanvas(Object e) {
	     if (e instanceof Canvas)
	            this.canvas = (Canvas)e;
	}
	public void setLayout(Rectangle r) {
	     if (root == null)
	            return;
	     root.setLayout(r);
	}
	@Override
	public boolean canExecute() {
	     if (root == null || canvas == null)
	            return false;
	     return true;
	}

	@Override
	public void execute() {
	     canvas.addChild(root);
	}
	@Override
	public boolean canUndo() {
	     if (root == null || canvas == null)
	           return false;
	     return canvas.contains(root);
	}
	@Override
	public void undo() {
	     canvas.removeChild(root);
	}

}
